package array;

import java.util.Arrays;
import java.util.Comparator;

public class leetCode179_largestNumber {

    public String largestNumber(int[] nums) {
        if(nums == null || nums.length == 0) return "";
        String[] s = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            s[i] = "" + nums[i];
        }
        Arrays.sort(s, new Comparator<String>() {
            @Override
            public int compare(String a, String b) {
                String x = a + b;
                String y = b + a;
                return y.compareTo(x);
            }
        });

        StringBuilder sb = new StringBuilder();
        for (String str : s) {
            sb.append(str);
        }
        int len = sb.length();
        int k = 0;
        while (k < len - 1 && sb.charAt(k) == '0'){
            k++;
        }
        return sb.substring(k);


    }


}
